﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x02000543 RID: 1347
	public class CameraLightCtrl : MonoBehaviour
	{
		// Token: 0x17000433 RID: 1075
		// (get) Token: 0x06002275 RID: 8821 RVA: 0x000CFCA0 File Offset: 0x000CDEA0
		// (set) Token: 0x06002276 RID: 8822 RVA: 0x000CFCA8 File Offset: 0x000CDEA8
		public CameraLightCtrl.LightInfo lightMap
		{
			get
			{
				return this._lightMap;
			}
			set
			{
				this._lightMap = value;
				this.lightsInfo.active = (this._lightMap == null);
			}
		}

		// Token: 0x06002277 RID: 8823 RVA: 0x000CFCC8 File Offset: 0x000CDEC8
		public void Init()
		{
			if (this.isInit)
			{
				return;
			}
			this.buttonColor.onClick.AddListener(new UnityAction(this.OnClickColor));
			this.toggleShadow.onValueChanged.AddListener(new UnityAction<bool>(this.OnValueChangeShadow));
			this.sliderIntensity.onValueChanged.AddListener(new UnityAction<float>(this.OnValueChangeIntensity));
			this.inputIntensity.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditIntensity));
			this.buttonIntensity.onClick.AddListener(new UnityAction(this.OnClickIntensity));
			for (int i = 0; i < 2; i++)
			{
				int axis = i;
				this.sliderAxis[axis].onValueChanged.AddListener(delegate(float f)
				{
					this.OnValueChangeAxis(f, axis);
				});
				this.inputAxis[axis].onEndEdit.AddListener(delegate(string s)
				{
					this.OnEndEditAxis(s, axis);
				});
				this.buttonAxis[axis].onClick.AddListener(delegate()
				{
					this.OnClickAxis(axis);
				});
			}
			for (int j = 0; j < this.toggleMethod.Length; j++)
			{
				int no = j;
				this.toggleMethod[j].onValueChanged.AddListener(delegate(bool f)
				{
					this.OnValueChangeMethod(f, no);
				});
			}
			this.Reflect();
			this.isInit = true;
		}

		// Token: 0x06002278 RID: 8824 RVA: 0x000CFE54 File Offset: 0x000CE054
		public void Reflect()
		{
			this.lightsInfo.select = Singleton<Studio>.Instance.sceneInfo.cameraMethod;
			this.lightsInfo.active = (this._lightMap == null);
			this.lightsInfo.Reflect();
			if (this.lightMap != null)
			{
				this.lightMap.Reflect();
			}
		}

		// Token: 0x06002279 RID: 8825 RVA: 0x000CFEB0 File Offset: 0x000CE0B0
		private void OnClickColor()
		{
			Singleton<Studio>.Instance.colorMenu.updateColorFunc = null;
			Singleton<Studio>.Instance.colorMenu.SetColor(Singleton<Studio>.Instance.sceneInfo.cameraLightColor, UI_ColorInfo.ControlType.PresetsSample);
			Singleton<Studio>.Instance.colorMenu.updateColorFunc = new UI_ColorInfo.UpdateColor(this.OnValueChangeColor);
			Singleton<Studio>.Instance.colorPaletteCtrl.visible = true;
		}

		// Token: 0x0600227A RID: 8826 RVA: 0x000CFF18 File Offset: 0x000CE118
		private void OnValueChangeColor(Color _color)
		{
			this.buttonColor.image.color = _color;
			Singleton<Studio>.Instance.sceneInfo.cameraLightColor = _color;
			this.Reflect();
		}

		// Token: 0x0600227B RID: 8827 RVA: 0x000CFF44 File Offset: 0x000CE144
		private void OnValueChangeShadow(bool _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			Singleton<Studio>.Instance.sceneInfo.cameraLightShadow = _value;
			this.Reflect();
		}

		// Token: 0x0600227C RID: 8828 RVA: 0x000CFF68 File Offset: 0x000CE168
		private void OnValueChangeIntensity(float _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			Singleton<Studio>.Instance.sceneInfo.cameraLightIntensity = _value;
			this.inputIntensity.text = _value.ToString("0.00");
			this.Reflect();
		}

		// Token: 0x0600227D RID: 8829 RVA: 0x000CFFA4 File Offset: 0x000CE1A4
		private void OnEndEditIntensity(string _text)
		{
			float num = Mathf.Clamp(Utility.StringToFloat(_text), 0.1f, 2f);
			Singleton<Studio>.Instance.sceneInfo.cameraLightIntensity = num;
			this.sliderIntensity.value = num;
			this.Reflect();
		}

		// Token: 0x0600227E RID: 8830 RVA: 0x000CFFEC File Offset: 0x000CE1EC
		private void OnClickIntensity()
		{
			Singleton<Studio>.Instance.sceneInfo.cameraLightIntensity = 1f;
			this.sliderIntensity.value = 1f;
			this.inputIntensity.text = Singleton<Studio>.Instance.sceneInfo.cameraLightIntensity.ToString("0.00");
			this.Reflect();
		}

		// Token: 0x0600227F RID: 8831 RVA: 0x000D0048 File Offset: 0x000CE248
		private void OnValueChangeAxis(float _value, int _axis)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			Singleton<Studio>.Instance.sceneInfo.cameraLightRot[_axis] = _value;
			this.inputAxis[_axis].text = _value.ToString("000");
			this.Reflect();
		}

		// Token: 0x06002280 RID: 8832 RVA: 0x000D0088 File Offset: 0x000CE288
		private void OnEndEditAxis(string _text, int _axis)
		{
			float num = Mathf.Clamp(Utility.StringToFloat(_text), 0f, 359f);
			Singleton<Studio>.Instance.sceneInfo.cameraLightRot[_axis] = num;
			this.sliderAxis[_axis].value = num;
			this.Reflect();
		}

		// Token: 0x06002281 RID: 8833 RVA: 0x000D00D4 File Offset: 0x000CE2D4
		private void OnClickAxis(int _axis)
		{
			Singleton<Studio>.Instance.sceneInfo.cameraLightRot[_axis] = 0f;
			this.sliderAxis[_axis].value = 0f;
			this.inputAxis[_axis].text = Singleton<Studio>.Instance.sceneInfo.cameraLightRot[_axis].ToString("000");
			this.Reflect();
		}

		// Token: 0x06002282 RID: 8834 RVA: 0x000D013C File Offset: 0x000CE33C
		private void OnValueChangeMethod(bool _isOn, int _no)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (!_isOn)
			{
				return;
			}
			Singleton<Studio>.Instance.sceneInfo.cameraMethod = _no;
			this.Reflect();
		}

		// Token: 0x06002283 RID: 8835 RVA: 0x000D0168 File Offset: 0x000CE368
		private void OnEnable()
		{
			this.isUpdateInfo = true;
			this.buttonColor.image.color = Singleton<Studio>.Instance.sceneInfo.cameraLightColor;
			this.sliderIntensity.value = Singleton<Studio>.Instance.sceneInfo.cameraLightIntensity;
			this.inputIntensity.text = Singleton<Studio>.Instance.sceneInfo.cameraLightIntensity.ToString("0.00");
			for (int i = 0; i < 2; i++)
			{
				this.sliderAxis[i].value = Singleton<Studio>.Instance.sceneInfo.cameraLightRot[i];
				this.inputAxis[i].text = Singleton<Studio>.Instance.sceneInfo.cameraLightRot[i].ToString("000");
			}
			this.toggleShadow.isOn = Singleton<Studio>.Instance.sceneInfo.cameraLightShadow;
			this.toggleMethod[Singleton<Studio>.Instance.sceneInfo.cameraMethod].isOn = true;
			this.isUpdateInfo = false;
		}

		// Token: 0x06002284 RID: 8836 RVA: 0x000D0274 File Offset: 0x000CE474
		private void Start()
		{
			this.Init();
		}

		// Token: 0x04002396 RID: 9110
		[SerializeField]
		private CameraLightCtrl.LightsInfo lightsInfo = new CameraLightCtrl.LightsInfo();

		// Token: 0x04002397 RID: 9111
		private CameraLightCtrl.LightInfo _lightMap;

		// Token: 0x04002398 RID: 9112
		[SerializeField]
		private Button buttonColor;

		// Token: 0x04002399 RID: 9113
		[SerializeField]
		private Toggle toggleShadow;

		// Token: 0x0400239A RID: 9114
		[SerializeField]
		private Slider sliderIntensity;

		// Token: 0x0400239B RID: 9115
		[SerializeField]
		private InputField inputIntensity;

		// Token: 0x0400239C RID: 9116
		[SerializeField]
		private Button buttonIntensity;

		// Token: 0x0400239D RID: 9117
		[SerializeField]
		private Slider[] sliderAxis;

		// Token: 0x0400239E RID: 9118
		[SerializeField]
		private InputField[] inputAxis;

		// Token: 0x0400239F RID: 9119
		[SerializeField]
		private Button[] buttonAxis;

		// Token: 0x040023A0 RID: 9120
		[SerializeField]
		private Toggle[] toggleMethod;

		// Token: 0x040023A1 RID: 9121
		private bool isUpdateInfo;

		// Token: 0x040023A2 RID: 9122
		private bool isInit;

		// Token: 0x02000544 RID: 1348
		[Serializable]
		public class LightInfo
		{
			// Token: 0x17000434 RID: 1076
			// (set) Token: 0x06002286 RID: 8838 RVA: 0x000D0284 File Offset: 0x000CE484
			public bool enable
			{
				set
				{
					if (this.transRoot.gameObject.activeSelf != value)
					{
						this.transRoot.gameObject.SetActive(value);
					}
				}
			}

			// Token: 0x17000435 RID: 1077
			// (get) Token: 0x06002287 RID: 8839 RVA: 0x000D02B0 File Offset: 0x000CE4B0
			// (set) Token: 0x06002288 RID: 8840 RVA: 0x000D02B8 File Offset: 0x000CE4B8
			public int shadowIdx
			{
				get
				{
					return this._shadowIdx;
				}
				set
				{
					this._shadowIdx = value;
				}
			}

			// Token: 0x06002289 RID: 8841 RVA: 0x000D02C4 File Offset: 0x000CE4C4
			public void Reflect()
			{
				foreach (Light light in this.light)
				{
					light.color = Singleton<Studio>.Instance.sceneInfo.cameraLightColor;
					light.intensity = Singleton<Studio>.Instance.sceneInfo.cameraLightIntensity;
				}
				this.transRoot.localRotation = Quaternion.Euler(Singleton<Studio>.Instance.sceneInfo.cameraLightRot[0], Singleton<Studio>.Instance.sceneInfo.cameraLightRot[1], 0f);
				this.light[this.shadowIdx].shadows = ((!Singleton<Studio>.Instance.sceneInfo.cameraLightShadow) ? LightShadows.None : LightShadows.Soft);
				this.alloyAreaLight.Color = Singleton<Studio>.Instance.sceneInfo.cameraLightColor;
				this.alloyAreaLight.Intensity = Singleton<Studio>.Instance.sceneInfo.cameraLightIntensity;
				this.alloyAreaLight.UpdateBinding();
			}

			// Token: 0x040023A3 RID: 9123
			public Light[] light;

			// Token: 0x040023A4 RID: 9124
			public AlloyAreaLight alloyAreaLight;

			// Token: 0x040023A5 RID: 9125
			public Transform transRoot;

			// Token: 0x040023A6 RID: 9126
			private int _shadowIdx;

			// Token: 0x02000545 RID: 1349
			public class LightParam
			{
				// Token: 0x0600228A RID: 8842 RVA: 0x000D03C0 File Offset: 0x000CE5C0
				public LightParam(Light _light)
				{
					this.light = _light;
					this.defaultIntensity = _light.intensity;
					this.defaultColor = _light.color;
				}

				// Token: 0x040023A7 RID: 9127
				public Light light;

				// Token: 0x040023A8 RID: 9128
				public float defaultIntensity = 1f;

				// Token: 0x040023A9 RID: 9129
				public Color defaultColor = Color.white;
			}
		}

		// Token: 0x02000546 RID: 1350
		[Serializable]
		public class LightsInfo
		{
			// Token: 0x17000436 RID: 1078
			// (get) Token: 0x0600228C RID: 8844 RVA: 0x000D0414 File Offset: 0x000CE614
			// (set) Token: 0x0600228D RID: 8845 RVA: 0x000D041C File Offset: 0x000CE61C
			public int select
			{
				get
				{
					return this._select;
				}
				set
				{
					this._select = value;
				}
			}

			// Token: 0x17000437 RID: 1079
			// (set) Token: 0x0600228E RID: 8846 RVA: 0x000D0428 File Offset: 0x000CE628
			public bool active
			{
				set
				{
					if (value)
					{
						for (int i = 0; i < this.infos.Length; i++)
						{
							this.infos[i].enable = (i == this._select);
						}
					}
					else
					{
						foreach (CameraLightCtrl.LightInfo lightInfo in this.infos)
						{
							lightInfo.enable = false;
						}
					}
				}
			}

			// Token: 0x0600228F RID: 8847 RVA: 0x000D0498 File Offset: 0x000CE698
			public void Reflect()
			{
				foreach (CameraLightCtrl.LightInfo lightInfo in this.infos)
				{
					lightInfo.Reflect();
				}
			}

			// Token: 0x040023AA RID: 9130
			public CameraLightCtrl.LightInfo[] infos = new CameraLightCtrl.LightInfo[2];

			// Token: 0x040023AB RID: 9131
			private int _select;
		}
	}
}
